package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.AdminService;
import com.tarena.lbs.pojo.basic.param.AdminParam;
import com.tarena.lbs.pojo.basic.query.AdminQuery;
import com.tarena.lbs.pojo.basic.vo.AdminVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class AdminController {

    @Autowired
    private AdminService adminService;

    //后台登录用例 admin账号详情查询
    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> detail() throws BusinessException {
        //String jwt=request.getHeader("Authorization");
        //log.info("当前头携带的jwt:{}",jwt);
        AdminVO vo = adminService.detail();
        return new Result<>(vo);
    }

    //查询后台管理的 账号列表
    @PostMapping("/admin/basic/role/list")
    public Result<PageResult<AdminVO>> adminPage(@RequestBody AdminQuery query) throws BusinessException{
        PageResult<AdminVO> voPage= adminService.adminPage(query);
        return new Result<>(voPage);
    }

    //后台新增账号
    @PostMapping("/admin/basic/role/add")
    public Result<Void> adminSave(@RequestBody AdminParam adminParam) throws BusinessException {
        adminService.adminSave(adminParam);
        return Result.success();
    }

}
